#!/home/hadoop/python26/bin/python
import json
import sys

last_key = ''
local_buffer = []
local_n = 0
local_t = 0
for line in sys.stdin:
    w = line.strip().split('\t')
    if len(w) == 2:
        key = str(w[0])
        body = w[1]
        r = None
        try:
            r = json.loads(body)
        except:
            continue
        if r != None:
            if last_key != key and last_key != '':
                if len(local_buffer) > 1 and local_n > 0 and local_t > 0:
                    dump_str = '\t'.join(local_buffer)
                    print last_key+'\t'+dump_str
                local_buffer = []
                local_n = 0
                local_t = 0
            last_key = key
            local_buffer.append(body)
            table_id = r['table_id']
            if table_id == 'neighbor':
                local_n += 1
            else:
                local_t += 1
        
